{
  "name": "Case 7 – Legal Case Merit Assessment",
  "nodes": [
    {
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2,
      "position": [0, 0],
      "parameters": {
        "formTitle": "Legal Case Submission – Merit Assessment",
        "formDescription": "Upload legal case documents for preliminary merit evaluation",
        "formFields": {
          "values": [
            { "fieldLabel": "Client Name", "requiredField": true },
            { "fieldLabel": "Email id", "fieldType": "email", "requiredField": true },
            {
              "fieldLabel": "Case_Documents",
              "fieldType": "file",
              "acceptFileTypes": ".pdf",
              "requiredField": true
            }
          ]
        }
      }
    },
    {
      "name": "Upload file",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [220, 0],
      "parameters": {
        "inputDataFieldName": "Case_Documents",
        "name": "={{ $json['Client Name'] + '_Legal_Case_Dossier' }}",
        "folderId": "REPLACE_WITH_LEGAL_CASES_FOLDER_ID"
      }
    },
    {
      "name": "Download file",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [420, 0],
      "parameters": {
        "operation": "download",
        "fileId": "={{ $json.id }}"
      }
    },
    {
      "name": "Extract Case Documents",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [620, 0],
      "parameters": {
        "operation": "pdf"
      }
    },
    {
      "name": "Download Legal Evaluation Criteria",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [820, 0],
      "parameters": {
        "operation": "download",
        "fileId": "REPLACE_WITH_LEGAL_CRITERIA_FILE_ID"
      }
    },
    {
      "name": "Extract Legal Criteria",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [1020, 0],
      "parameters": {
        "operation": "pdf"
      }
    },
    {
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [220, 260],
      "parameters": {
        "promptType": "define",
        "text": "=Client Case Documents:\n{{ $('Extract Case Documents').item.json.text }}\n\nLegal Evaluation Criteria & Reference Judgments:\n{{ $('Extract Legal Criteria').item.json.text }}",
        "options": {
          "systemMessage": "You are a Senior Litigation Partner at a law firm.\n\nYOUR OBJECTIVE:\nDecide whether the firm should accept representation based on legal merit, probability of success, and commercial viability.\n\nANALYSIS FRAMEWORK (MANDATORY):\n1. FACT STRENGTH – quality of documentary evidence, admissions, and consistency of facts.\n2. LEGAL PRECEDENT – alignment with favourable past judgments in similar matters.\n3. JURISDICTIONAL RISK – court tendencies, timelines, and enforceability.\n4. DEFENCE STRENGTH – strength of counterparty’s likely legal defences.\n5. COMMERCIAL RECOVERY – realistic recoverability of claim amount.\n\nYOU MUST PRODUCE ONE JSON OBJECT WITH EXACTLY THESE FIELDS. ALL FIELDS ARE MANDATORY.\n\nJSON SCHEMA (STRICT):\n{\n  \"Case_ID\": \"string\",\n  \"Client_Name\": \"string\",\n  \"Case_Type\": \"string\",\n  \"Claim_Amount_INR_Cr\": \"number\",\n  \"Strength_of_Evidence\": \"Weak | Moderate | Strong\",\n  \"Legal_Precedent_Alignment\": \"Low | Medium | High\",\n  \"Jurisdictional_Risk\": \"Low | Medium | High\",\n  \"Counterparty_Defence_Strength\": \"Weak | Moderate | Strong\",\n  \"Estimated_Probability_of_Success_Percentage\": \"number\",\n  \"Commercial_Viability\": \"Low | Medium | High\",\n  \"Firm_Recommendation\": \"Accept Case | Decline Representation\",\n  \"Partner_Remarks\": \"string\"\n}\n\nINSTRUCTIONS:\n- Numeric fields MUST contain numbers only.\n- Do NOT add, remove, or rename fields.\n- Output ONLY valid JSON.\n- IMMEDIATELY call the Google Sheets Append Row tool using this JSON."
        }
      }
    },
    {
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [0, 420],
      "parameters": {
        "model": {
          "mode": "list",
          "value": "gpt-4.1-mini"
        }
      }
    },
    {
      "name": "Append row",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4,
      "position": [420, 460],
      "parameters": {
        "operation": "append",
        "documentId": "REPLACE_WITH_GOOGLE_SHEET_ID",
        "sheetName": "Legal Case Merit Assessment Register"
      }
    },
    {
      "name": "Send Email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2,
      "position": [420, 260],
      "parameters": {
        "sendTo": "={{ $('On form submission').item.json['Email id'] }}",
        "subject": "Legal Case Merit Assessment – Outcome",
        "message": "={{ 'Dear ' + $('On form submission').item.json['Client Name'] + ',<br><br>Your legal matter has been reviewed by our senior litigation team. We will contact you shortly regarding representation.<br><br>Regards,<br>Legal Review Committee' }}"
      }
    }
  ],
  "connections": {
    "On form submission": { "main": [[{ "node": "Upload file" }]] },
    "Upload file": { "main": [[{ "node": "Download file" }]] },
    "Download file": { "main": [[{ "node": "Extract Case Documents" }]] },
    "Extract Case Documents": { "main": [[{ "node": "Download Legal Evaluation Criteria" }]] },
    "Download Legal Evaluation Criteria": { "main": [[{ "node": "Extract Legal Criteria" }]] },
    "Extract Legal Criteria": { "main": [[{ "node": "AI Agent" }]] },
    "OpenAI Chat Model": { "ai_languageModel": [[{ "node": "AI Agent" }]] },
    "Append row": { "ai_tool": [[{ "node": "AI Agent" }]] },
    "AI Agent": { "main": [[{ "node": "Send Email" }]] }
  },
  "active": false
}
